package sg.edu.nus.iss.team8s.vmcs.Listener;
/**
 * 
 * @author Nie Xiaoyi
 * 
 */
import java.awt.TextComponent;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;

import sg.edu.nus.iss.team8s.vmcs.control.StoreController;

public class StoreViewerListener implements TextListener{

	private int type,identidier;
	private int value;
	public StoreViewerListener(int type,int identidier,int value){
		this.type = type;
		this.identidier = identidier;
		this.value = value;
	}
	

	public void textValueChanged(TextEvent e) {
		// TODO Auto-generated method stub
		TextComponent tc = (TextComponent)e.getSource();
	    String quantity = tc.getText();	 
	    if(isInteger(quantity)){
		    if(value != Integer.parseInt(quantity))
		    	StoreController.changeStoreQuantity(type, identidier, Integer.parseInt(quantity));
	    }
	}
	
	private boolean isInteger(String str){
		try {
			Integer.parseInt(str);
			return true;
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			return false;
		}
	}

}
